﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
using pointType = TutorialPointer.pointType;
public class FingerMoveNode : TutorialNode
{
    [JsonAttribute("s_type", "起始位置类型")]
    public ElementType startPosType = ElementType.ScreenPercent;

    [JsonAttribute("rect", "起始位置(相对于屏幕的比列)", "s_type","", "ScreenPercent")]
    public Vector2 startPoint = new Vector2();

    [JsonAttribute("s_aridx", "起始位置(格子矩形)", "s_type", "", "areaIndex")]
    public Rect start_areaIndex = new Rect();

    [JsonAttribute("s_buildingID", "起始位置(建筑ID)", "s_type", "", "buildingID")]
    public int start_BuildingID = 0;

    [JsonAttribute("s_uiPath", "起始位置(UI路径)", "s_type", "UIprefab对象, 子节点路径", "uiPath")]
    public List<string> start_uiPath = new List<string>() { "", "" };


    [JsonAttribute("e_type", "结束位置类型")]
    public ElementType endPosType = ElementType.ScreenPercent;

    [JsonAttribute("path", "结束点(相对于屏幕的比例)", "e_type", "", "ScreenPercent")]
    public Vector2 pointEnd = new Vector2();

    [JsonAttribute("e_aridx", "结束点(格子矩形)", "e_type", "", "areaIndex")]
    public Rect end_areaIndex = new Rect();

    [JsonAttribute("e_buildingID", "起始位置(建筑ID)", "e_type", "", "buildingID")]
    public int end_BuildingID = 0;

    [JsonAttribute("e_uiPath", "结束位置(UI路径)", "e_type", "UIprefab对象, 子节点路径", "uiPath")]
    public List<string> end_uiPath = new List<string>() { "", "" };

    [JsonAttribute("time", "移动总时间")]
    public float duration = 0f;

    [JsonAttribute("rept", "是否重复")]
    public bool Repeat = false;

    [JsonAttribute("cinput", "是否根据手指状态展示动画")]
    public bool checkInput = false;

    [JsonAttribute("sttm", "起始等待时间")]
    public float startTime = 0;

    [JsonAttribute("sttp", "起始状态")]
    public pointType startType = pointType.normal;

#if UNITY_EDITOR
    [JsonEditorAttribute(typeof(UIPathSwitchMember), "s_uiPath")]
    public List<object> s_uiPath = new List<object>();
#endif

#if UNITY_EDITOR 
    [JsonEditorAttribute(typeof(UIPathSwitchMember), "e_uiPath")]
    public List<object> e_uiPath = new List<object>();
#endif

    /// <summary>
    /// 移动信息
    /// </summary>
    public struct moveInfo
    {
        public ElementType startPosType;
        
        public Vector2 start_SceenPercent;
        
        public Rect start_areaIndex ;
        
        public int start_BuildingID ;
        
        public List<string> start_uiPath ;

        
        public ElementType endPosType;

        public Vector2 end_SceenPercent;

        public Rect end_areaIndex ;

        public int end_BuildingID ;

        public List<string> end_uiPath ;

        public void Init(FingerMoveNode node)
        {
            this.startPosType = node.startPosType;
            switch (this.startPosType)
            {
                case ElementType.ScreenPercent:
                    this.start_SceenPercent = node.startPoint;
                    break;
                case ElementType.areaIndex:
                    this.start_areaIndex = node.start_areaIndex;
                    break;
                case ElementType.buildingID:
                    this.start_BuildingID = node.start_BuildingID;
                    break;
                case ElementType.uiPath:
                    this.start_uiPath = node.start_uiPath;
                    break;
                default:
                    break;
            }

            this.endPosType = node.endPosType;
            switch (this.endPosType)
            {
                case ElementType.ScreenPercent:
                    this.end_SceenPercent = node.pointEnd;
                    break;
                case ElementType.areaIndex:
                    this.end_areaIndex = node.end_areaIndex;
                    break;
                case ElementType.buildingID:
                    this.end_BuildingID = node.end_BuildingID;
                    break;
                case ElementType.uiPath:
                    this.end_uiPath = node.end_uiPath;
                    break;
                default:
                    break;
            }
        }
        public static moveInfo GetInfo(FingerMoveNode node)
        {
            moveInfo info = new moveInfo();
            info.Init(node);
            return info;
        }
    }


    protected override void Init()
    {
        TutorialUIManager.Instance.ShowFingerMove(moveInfo.GetInfo(this), startTime, duration, startType);
    }

    protected override void Cancel()
    {
        TutorialUIManager.Instance.HideFingerMove();
    }
}

